<style lang="scss" scoped>
    @import '../../css/resource.scss';

    .count-box{text-align: center;display: inline-block;}
    .minus-plus-btn{float: left;border:1px solid #aaa;background: #fcfdff;width: 20px;height: 28px;line-height: 28px;cursor: pointer;}
    .icon-font{font-size: 6px;}
    .book-count{float: left;width: 40px;height: 26px;line-height: 26px;border:none;border-top:1px solid #aaa;border-bottom: 1px solid #aaa;text-align: center;outline: none;}
    .count-word{margin: 8px 20px 0 0;}
    .bookinfo-abstract{color: #666;font-size: 14px;margin: 8px 0 8px 0;@include maxLine(1, 22px);height: 22px;}
    .list-title{float: left;margin-top: 1px;}
    .list-title1{float: left;margin-top: 6px;}
</style>

<template>

    <section>

        <section class="books-info book-box mt">
            <div class="bookinfo-box clearfix">
                <div class="bookinfo-cover fl">
                    <img :src="resourceInfo.ResourceCover" alt="">
                </div>
                <div class="bookinfo-info">
                    <h6 class="fs-18 bookinfo-infotitle">{{resourceInfo.ResourceName}}</h6>
                    <p class="bookinfo-abstract">{{resourceInfo.ResourceSubTitle}}</p>
                    <div class="bookinfo-minor p-rela mt">
                        <div class="bim-count p-abso fs-14 bim-text" v-show="resourceInfo.OrderNum!=0"><span class="fs-18">{{resourceInfo.OrderNum}}</span><br>订购量</div>
                        <div class="fs-14 bim-text">
                            <span class="mr20 list-title1">价格</span>
                            <template v-for="item in resourceInfo.PriceList">
                                <span class="bim-textlist"><span class="bim-num">￥</span><span class="bim-num fs-20 ">{{item}}</span></span>
                            </template>

                        </div>
                        <div class="fs-14 bim-text mt" v-show="resourceInfo.PriceList?resourceInfo.PriceList.length>1:''">
                            <span class="mr20 list-title">数量</span>
                            <template v-for="item in resourceInfo.NumList">
                                <span class="bim-textlist">{{item}}人份</span>
                            </template>
                        </div>
                        <div class="fs-14 bim-text mt">
                            <span class="mr20 list-title">{{ resourceInfo.ResSubCateID == '8' ? '讲师':'作者' }}</span>
                            <span class="bim-textlist">{{resourceInfo.Author?resourceInfo.Author:'暂无'}}</span>
                            <span class="bim-textlist" v-if="resourceInfo.ResSubCateID != 8">出版社 {{resourceInfo.Publisher?resourceInfo.Publisher:'暂无'}}</span>
                            <span class="bim-textlist" v-if="resourceInfo.ResSubCateID != 8">出版时间 {{resourceInfo.PublishTime?resourceInfo.PublishTime:'暂无'}}</span>
                        </div>
                    </div>
                    <div class="bookinfo-num mt20 bim-text fs-12">
                        <div class="count-box clearfix">
                            <span class="count-word fl">数量</span>
                            <span class="minus-plus-btn" @click="countMinus"><i class="el-icon-minus icon-font"></i></span>
                            <input type="text" class="book-count" v-model="count" @change="countChange">
                            <span class="minus-plus-btn" @click="countPlus"><i class="el-icon-plus icon-font"></i></span>
                        </div>
                        <div class="mt fs-12">备注：*份数为购买者所属部门人员总和</div>
                    </div>

                    <div class="bookinfo-dobox mt30">
                        <span class="bid-one bid-two" @click="addCar">加入购物车</span>
                    </div>
                </div>
            </div>


            <div class="book-tit mt20">
                <span class="booktit-text">书籍简介</span>
            </div>
            <div class="btt-content" v-html="resourceInfo.ResourceAbstract"></div>

        </section>

    </section>

</template>

<script>

	import qs from 'qs'
    import com from 'js/common.js'

	export default{
		data: function(){
			return {
                resourceID:this.$route.query.resourceID||'',
                resourceInfo:{},
                count:'',
                path: [
                    {
                        'name':'资源管理',
                        'path':'/resource/book-list'
                    },
                    {
                        'name':'资源库',
                        'path':'/resource/book-list'
                    },
                    {
                        'name': '资源详情',

                    }
                ],
            }
		},
		mixins: [mixinMethods],
		methods: {
		    addCar(){
                axios.post('/com/orders/addCart', qs.stringify({
                    resourceID: this.resourceID,
                    num:this.count
                })).then((res) => {
                    var d = res.data;
                    if(d.flag == 1){
                        this.$message.success('已添加到购物车')
                        this.$emit('ievent',d.data.NowNum);
                    }else {
                        this.$message.error(d.msg)
                    }
                })
            },
            countMinus(){
                if(this.count>1){
                    this.count--;
                }
            },
            countPlus(){
                this.count++
            },
            countChange(){
                if(typeof(Number(this.count))!='number'||this.count<1){
                    this.count = 1;
                }
            }
		},
		mounted: function(){
            this.$store.commit('setPath', this.path)
            axios.post('/com/resource/systemResDetail', qs.stringify({
                resourceID: this.resourceID
            })).then((res) => {
                var d = res.data;
                if(d.flag == 1){
                    this.count = d.data.Count;
                    this.resourceInfo = d.data.ResourceInfo;
                    let ResourcePrice = eval("("+ this.resourceInfo.ResourcePrice +")") ;
                    this.resourceInfo.PriceList = [];
                    this.resourceInfo.NumList = [];
                    ResourcePrice.forEach((item)=>{
                        this.resourceInfo.PriceList.push(item.price)
                        this.resourceInfo.NumList.push(item.num)
                    })

                    com.getFullOssFiles([{url:this.resourceInfo.ResourceCover,param:'image/resize,m_fixed,h_260,w_180'}],(fullUrlArr)=>{
                        this.resourceInfo.ResourceCover = fullUrlArr[0]
                    })

                }else {
                    this.$message.error(d.msg)
                }
            })
		}
	}


</script>
